<template>
  <div class="wrap">
    <header>
      <span @click="go()">&lt;</span>
      <p>楼市圈</p>
    </header>
    <main>
      <div class="pro">
        <div v-for="(item,index) in list" :key="index">
          <div class="p1">
            <div class="p11">
              <img :src="item.img" alt />
              <b>{{item.name}}</b>
            </div>
            <div class="p12">
              <div class="left">
                <h4>10月</h4>
                <p>10-28</p>
              </div>
              <div class="right">
                <p>{{item.title}}</p>
                <img :src="item.img" alt />
                <p class="del" @click="del(item.id)">删除</p>
              </div>
            </div>
          </div>
        </div>
        <div class="p2">
          <van-icon name="plus" @click="add()" />
        </div>
      </div>
    </main>
    <el-dialog title :visible.sync="dialog" width="90%">
      <el-form :model="obj">
        <el-input v-model="obj.name" placeholder="姓名"></el-input>
        <el-input v-model="obj.title" placeholder="标题"></el-input>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleFalse()">取 消</el-button>
        <el-button type="primary" @click="handleOk()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import axios from "../../utils/request";
export default {
  data() {
    return {
      list: [],
      dialog: false,
      obj: {
        name: "",
        title: "",
        img: ""
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    go() {
      this.$router.go(-1);
    },
    getList() {
      axios({
        url: "/api/getList",
        method: "post"
      }).then(res => {
        // console.log(res);
        this.list = res.data.data;
      });
    },
    //删除
    del(id) {
      axios({
        url: "/api/delList",
        method: "post",
        data: { id }
      }).then(res => {
        // console.log(res);
        this.getList();
        // alert("删除成功");
      });
    },
    //添加按钮
    add() {
      this.dialog = true;
      this.obj.img =
        "https://img0.baidu.com/it/u=1246802697,1936907220&fm=26&fmt=auto&gp=0.jpg";
      this.obj.name="";
      this.obj.title="";
    },
    //遮罩确定
    handleOk() {
      this.dialog = false;
      axios({
        url: "/api/addList",
        method: "post",
        data: this.obj
      }).then(res => {
        console.log(res);
        this.getList();
      });
    },
    //取消
    handleFalse() {
      this.dialog = false;
    },
  }
};
</script>

<style lang="scss" scoped>
.wrap {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  left: 0;
  top: 0;
}
header {
  width: 100%;
  height: 50px;
  display: flex;
  line-height: 50px;
  align-items: center;
  background: rgb(56, 121, 240);
  padding: 15px;
  color: #fff;
  p {
    padding-left: 38%;
  }
}
main {
  flex: 1;
  overflow-y: scroll;
  .pro {
    width: 90%;
    margin: 0 5%;
    .p1 {
      padding: 10px;
      .p11 {
        display: flex;
        align-items: center;
        margin-bottom: 30px;
        img {
          width: 40px;
          height: 40px;
          border-radius: 50%;
        }
        b {
          padding-left: 10px;
        }
      }
      .p12 {
        display: flex;
        .left {
          h4 {
            font-size: 16px;
          }
          p {
            font-size: 14px;
            padding-top: 5px;
            color: #999;
          }
        }
        .right {
          margin-left: 20px;
          border-bottom: 1px solid #ccc;
          p {
            font-size: 16px;
            color: #333;
          }
          img {
            width: 250px;
            height: 140px;
            margin-top: 10px;
          }
          .del {
            font-size: 14px;
            color: cornflowerblue;
            padding: 15px 40%;
          }
        }
      }
    }
    .p2 {
      width: 50px;
      height: 50px;
      line-height: 50px;
      background: rgb(56, 121, 240);
      border-radius: 50%;
      text-align: center;
      position: absolute;
      right: 20px;
      bottom: 20px;
      color: #fff;
    }
  }
}
</style>